#ifndef __FILE_MONITOR_IMP_H__
#define __FILE_MONITOR_IMP_H__
#include<vector>
#include<string>
#include<thread>
#include<Windows.h>
#include "CommonTask.h"

#define MAX_BUFFER  40960

struct DIR_CHANGE_MSG
{
    DWORD           dwAction;
    std::string     strFilePath;
};

typedef struct _DIRECTORY_INFO
{
    HANDLE          hDir;
    std::wstring    wstrDirName;
    CHAR            lpBuffer[MAX_BUFFER];
    DWORD           dwBufLength;
    OVERLAPPED      Overlapped;
}DIRECTORY_INFO, *PDIRECTORY_INFO, *LPDIRECTORY_INFO;

class CFileMonitorImp
{
    using MSG_QUEUE = CCommonTask<DIR_CHANGE_MSG>;
public:
    CFileMonitorImp();
    CFileMonitorImp(const std::vector<std::wstring> &vecMonitorDir);
    ~CFileMonitorImp();

    bool Init();
    void Start();

    void UnInit();
    
    bool HandleMessage(const DIR_CHANGE_MSG &msg);
private:
    void HandleDirectoryChange();
private:
    std::vector<std::wstring>       m_vecMonitorDir;
    std::vector<PDIRECTORY_INFO>    m_vecDirInfo;
    HANDLE                          m_hCompPort;
    std::thread                     m_thHandleMsg;
};
#endif
